/**
 * 
 */
package com.oron3.bouncer.objects;


import javax.microedition.khronos.opengles.GL10;

import com.oron3.bouncer.genericgl.GL3D;
import com.oron3.bouncer.genericgl.GLWorld;
import com.oron3.bouncer.genericgl.MatrixTrackingGL;
import com.oron3.bouncer.objects.shapes.Point;
import com.oron3.bouncer.objects.shapes.Rectangle;

/**
 * @author Ofek
 *
 */
public class GLRectangle extends Rectangle implements GLShape {
	private final GL3D gl3d = new GL3D();
	private final GL3D gl3dLines = new GL3D();
	private Color c;
	/**
	 * NOTE :  
	 * @param p1 
	 * @param p2
	 * @param p3
	 * @param p4
	 */
	public GLRectangle(final Point p1, final Point p2, final Point p3) {
		super(p1, p2, p3);
		final Point p4 = p2.add(p1.sub(p2).add(p3.sub(p2)));

		gl3dLines.add(p1);
		gl3dLines.add(p2);
		gl3dLines.add(p3);
		gl3dLines.add(p4);
		gl3dLines.add(0,1,1,2,2,3,3,0);
		gl3dLines.prepare();

		gl3d.points.add(p1);
		gl3d.points.add(p2);
		gl3d.points.add(p3);
		gl3d.points.add(p1);
		gl3d.points.add(p4);
		gl3d.points.add(p3);
		gl3d.prepare();
	}

	@Override
	public void draw(final MatrixTrackingGL gl) {
		gl.glColor4f(c.r,c.g, c.b, c.a);
		gl3d.draw(gl, GL10.GL_TRIANGLE_STRIP);
		gl.glColor4f(0f,0f, 0f, c.a);
		gl3dLines.draw(gl, GL10.GL_LINE_LOOP);
	}


	/* (non-Javadoc)
	 * @see com.oron3.bouncer.objects.GLShape#setColor(com.oron3.bouncer.objects.Color)
	 */
	@Override
	public void setColor(final Color c) {
		this.c = c;
	}

	/* (non-Javadoc)
	 * @see com.oron3.bouncer.objects.GLShape#step(float, com.oron3.bouncer.genericgl.GLWorld)
	 */
	@Override
	public void step(final float dt, final GLWorld glWorld) {
	}

}
